<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/xhtml;charset=UTF-8"/>
<meta http-equiv="X-UA-Compatible" content="IE=9"/>
<meta name="generator" content="Doxygen 1.8.11"/>
<title>Aria: netServerExample.cpp</title>
<link href="tabs.css" rel="stylesheet" type="text/css"/>
<script type="text/javascript" src="jquery.js"></script>
<script type="text/javascript" src="dynsections.js"></script>
<link href="navtree.css" rel="stylesheet" type="text/css"/>
<script type="text/javascript" src="resize.js"></script>
<script type="text/javascript" src="navtreedata.js"></script>
<script type="text/javascript" src="navtree.js"></script>
<script type="text/javascript">
  $(document).ready(initResizable);
  $(window).load(resizeHeight);
</script>
<link href="doxygen.css" rel="stylesheet" type="text/css" />
</head>
<body>
<div id="top"><!-- do not remove this div, it is closed by doxygen! -->
<div id="titlearea">
<table cellspacing="0" cellpadding="0">
 <tbody>
 <tr style="height: 56px;">
  <td id="projectalign" style="padding-left: 0.5em;">
   <div id="projectname">Aria
   &#160;<span id="projectnumber">2.9.1</span>
   </div>
  </td>
 </tr>
 </tbody>
</table>
</div>
<!-- end header part -->
<!-- Generated by Doxygen 1.8.11 -->
  <div id="navrow1" class="tabs">
    <ul class="tablist">
      <li><a href="index.html"><span>Main&#160;Page</span></a></li>
      <li><a href="pages.html"><span>Related&#160;Pages</span></a></li>
      <li><a href="modules.html"><span>Modules</span></a></li>
      <li><a href="annotated.html"><span>Classes</span></a></li>
      <li><a href="files.html"><span>Files</span></a></li>
      <li><a href="examples.html"><span>Examples</span></a></li>
    </ul>
  </div>
</div><!-- top -->
<div id="side-nav" class="ui-resizable side-nav-resizable">
  <div id="nav-tree">
    <div id="nav-tree-contents">
      <div id="nav-sync" class="sync"></div>
    </div>
  </div>
  <div id="splitbar" style="-moz-user-select:none;" 
       class="ui-resizable-handle">
  </div>
</div>
<script type="text/javascript">
$(document).ready(function(){initNavTree('netServerExample_8cpp-example.html','');});
</script>
<div id="doc-content">
<div class="header">
  <div class="headertitle">
<div class="title">netServerExample.cpp</div>  </div>
</div><!--header-->
<div class="contents">
<p>Shows how to use <a class="el" href="classArNetServer.html" title="Class for running a simple net server to send/recv commands via text. ">ArNetServer</a>, a simple text command receiver</p>
<div class="fragment"><div class="line"><span class="preprocessor">#include &quot;Aria.h&quot;</span></div><div class="line"></div><div class="line"><span class="comment">// To use the net server, start this program, then use the &#39;telnet&#39; program to connect to localhost</span></div><div class="line"><span class="comment">// on TCP port 7171 by running this command:</span></div><div class="line"><span class="comment">//   telnet localhost 7171</span></div><div class="line"><span class="comment">// When connected and prompted for a password, type in:</span></div><div class="line"><span class="comment">//   password</span></div><div class="line"><span class="comment">// and press enter.  Then you can enter a command. Use the &#39;help&#39; command to print available commands.</span></div><div class="line"><span class="comment">// For this program, try &quot;test&quot; and &quot;test2&quot; with and without additional arguments.</span></div><div class="line"><span class="comment">// ArNetServer is a simple way to provide a quick remote control interface for a robot control </span></div><div class="line"><span class="comment">// program running on the robot&#39;s onboard computer over wireless networking, if you don&#39;t want to </span></div><div class="line"><span class="comment">// use the ArNetworking library and MobileEyes. (You can provide both options in a program however, </span></div><div class="line"><span class="comment">// ArNetworking and ArNetServer use different TCP ports and will both run fine in the same program.)</span></div><div class="line"></div><div class="line"><span class="comment">// This function just prints out what the client entered and then sends some </span></div><div class="line"><span class="comment">// data back. You could modify it to, for example, control the robot with</span></div><div class="line"><span class="comment">// different commands.</span></div><div class="line"><span class="keywordtype">void</span> test(<span class="keywordtype">char</span> **argv, <span class="keywordtype">int</span> argc, <a name="_a0"></a><a class="code" href="classArSocket.html">ArSocket</a> *socket)</div><div class="line">{</div><div class="line">  <span class="keywordtype">int</span> i;</div><div class="line">  printf(<span class="stringliteral">&quot;Client said: &quot;</span>);</div><div class="line">  <span class="keywordflow">for</span> (i = 0; i &lt; argc; ++i)</div><div class="line">    printf(<span class="stringliteral">&quot;\t%s\n&quot;</span>, argv[i]);</div><div class="line">  printf(<span class="stringliteral">&quot;\n&quot;</span>);</div><div class="line">  socket-&gt;<a name="a1"></a><a class="code" href="classArSocket.html#a62c1a96eb8fa0dd1c384646228eac194">writeString</a>(<span class="stringliteral">&quot;Thank you, command received.&quot;</span>);</div><div class="line">}</div><div class="line"></div><div class="line"></div><div class="line"><span class="keywordtype">int</span> main(<span class="keywordtype">int</span> argc, <span class="keywordtype">char</span> **argv)</div><div class="line">{</div><div class="line">  <span class="comment">// Initialize Aria</span></div><div class="line">  <a name="a2"></a><a class="code" href="classAria.html#ad99c16b5d947229d9f8e1c5b2d4cdd73">Aria::init</a>();</div><div class="line">  <span class="comment">// we need a server</span></div><div class="line">  <a name="_a3"></a><a class="code" href="classArNetServer.html">ArNetServer</a> server;</div><div class="line">  <span class="comment">// a callback for our test function</span></div><div class="line">  <a name="_a4"></a><a class="code" href="classArGlobalFunctor3.html">ArGlobalFunctor3&lt;char **, int, ArSocket *&gt;</a> testCB(&amp;test);</div><div class="line"></div><div class="line">  <span class="comment">// start the server up without a robot on port 7171 with a password</span></div><div class="line">  <span class="comment">// of password and allow multiple clients</span></div><div class="line">  <span class="keywordflow">if</span> (!server.<a name="a5"></a><a class="code" href="classArNetServer.html#a2adba95c22d9c26a043607e0d9eca6fb">open</a>(NULL, 7171, <span class="stringliteral">&quot;password&quot;</span>, <span class="keyword">true</span>))</div><div class="line">  {</div><div class="line">    printf(<span class="stringliteral">&quot;Could not open server.\n&quot;</span>);</div><div class="line">    <a name="a6"></a><a class="code" href="classAria.html#a6abc3d39b3e9548063bb8e78375acc17">Aria::exit</a>(1);</div><div class="line">    <span class="keywordflow">return</span> 1;</div><div class="line">  }</div><div class="line">  </div><div class="line">  <span class="comment">// add our test command</span></div><div class="line">  server.<a name="a7"></a><a class="code" href="classArNetServer.html#afb0b05acf65940aa9901180c3d30d90f">addCommand</a>(<span class="stringliteral">&quot;test&quot;</span>, &amp;testCB, <span class="stringliteral">&quot;this simply prints out the command given on the server&quot;</span>);</div><div class="line">  server.<a class="code" href="classArNetServer.html#afb0b05acf65940aa9901180c3d30d90f">addCommand</a>(<span class="stringliteral">&quot;test2&quot;</span>, &amp;testCB, <span class="stringliteral">&quot;this simply prints out the command given on the server&quot;</span>);</div><div class="line">  </div><div class="line">  <span class="comment">//server.setLoggingDataSent(true);</span></div><div class="line">  <span class="comment">//server.setLoggingDataReceived(true);</span></div><div class="line">  <span class="comment">// run while the server is running</span></div><div class="line">  <span class="keywordflow">while</span> (server.<a name="a8"></a><a class="code" href="classArNetServer.html#a757cde3ca5c10e425b52947a40ec9576">isOpen</a>() &amp;&amp; <a name="a9"></a><a class="code" href="classAria.html#a573c386c42739be20fa97a99ae65f9ee">Aria::getRunning</a>())</div><div class="line">  {</div><div class="line">    server.<a name="a10"></a><a class="code" href="classArNetServer.html#a8e9492bc9ae8b1532e03011e905d17ef">runOnce</a>();</div><div class="line">    <a name="a11"></a><a class="code" href="group__easy.html#ga4dfb878a3f9123b8dd96ae05b2fd94cb">ArUtil::sleep</a>(1);</div><div class="line">  }</div><div class="line">  server.<a name="a12"></a><a class="code" href="classArNetServer.html#a585cbb215a87b295fe779b5a3f51a49d">close</a>();</div><div class="line">  <a class="code" href="classAria.html#a6abc3d39b3e9548063bb8e78375acc17">Aria::exit</a>(0);</div><div class="line">  <span class="keywordflow">return</span> 0;  </div><div class="line">}</div></div><!-- fragment --> </div><!-- contents -->
</div><!-- doc-content -->
<!-- start footer part -->
<div id="nav-path" class="navpath"><!-- id is needed for treeview function! -->
  <ul>
    <li class="footer">Generated by
    <a href="http://www.doxygen.org/index.html">
    <img class="footer" src="doxygen.png" alt="doxygen"/></a> 1.8.11 </li>
  </ul>
</div>
</body>
</html>
